﻿using Microsoft.Owin.Hosting;
using System;
using Topshelf;

namespace gt.webapi
{
    public class ServiceRunner : ServiceControl
    {
        private static IDisposable myServer;

        public bool Start(HostControl hostControl)
        {
            var bindUrl = "http://127.0.0.1:8000";
            myServer = WebApp.Start<Startup>(bindUrl);
            Console.WriteLine(string.Format("service start running at:{0}", bindUrl));
            return true;
        }

        public bool Stop(HostControl hostControl)
        {
            Console.WriteLine("service start stopped!");
            myServer.Dispose();

            return true;
        }
    }
}
